<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/12/6 0006
  Time: 9:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>获取web服务器属性</title>
</head>
<body>
<%--<%--%>
<%--    Context con=new InitialContext();--%>
<%--    String s=(String)con.lookup("java:comp/env/tjndi");--%>
<%--    out.print("JNDI:"+s);--%>
<%--%>--%>

<%
    Connection conn=null;
    try{
        Context ct=new InitialContext();
        DataSource ds=(DataSource) ct.lookup("java:comp/env/conMySql");
        conn=ds.getConnection();
        String selectString="select newId,newInfo from WSQ.news";
        PreparedStatement ps=conn.prepareStatement(selectString);
        ResultSet rs=ps.executeQuery();
        System.out.println(rs);
        while(rs.next()){
            out.print(rs.getInt(1));
            out.print(rs.getString(2)+"\n");
        }
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }
%>
</body>
</html>
